import {
  login
} from '@/services'
import { setToken } from '@/utils';

const state = {
  info: {}
};

const getters = {};

const mutations = {
  update(state, payload) {
    for (let key in payload) {
      state[key] = payload[key];
    }
  }
};

const actions = {
  async login({ commit }, payload) {
    let result = await login(payload);
    console.log(result);
    if (result) {
      commit('update', { info: result });
      setToken(result.access_token);
    }
  }
};

export default {
  namespaced: true,
  modules: {},
  state,
  getters,
  mutations,
  actions,
}